package com.ms.p2p.template.directive;

import com.alibaba.dubbo.config.annotation.Reference;
import com.ms.common.utils.DirectiveUtils;
import com.ms.p2p.bean.PageBean;
import com.ms.p2p.provider.LoanProvider;
import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;
import org.springframework.stereotype.Repository;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * Created by xing_ on 2017/5/21.
 */
@Repository
public class LoanDirective extends BaseDirective {

    @Reference
    private LoanProvider loanProvider;


    public static final String TYPE = "typeId";

    @Override
    public void execute(Environment env, Map params, TemplateModel[] templateModels,
                        TemplateDirectiveBody body) throws TemplateException, IOException {

        Integer typeId = DirectiveUtils.getInt(TYPE, params);
        Integer count = getCount(params);
        PageBean page = new PageBean();
        page.setPageSize(count);
        List<Map<String,Object>>  list = loanProvider.findPager(null,null,null, typeId, null, null, null, null, null, null, null, null,null,null, page);
        renderParamToBody("loans", list, env, body);
    }
}
